﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{
    public partial class Form2 : Form
    {
        DataSet ds = new DataSet();
        string userid,strsql, mawb_no, location, carrier, flight_no, flight_date = "";
        public WebPor.Service1 lc = new WebPor.Service1();
        public Form2(string user)
        {
            InitializeComponent();
            textBox4.Focus();
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "ddMMMyy";
            flight_date = dateTimePicker1.Text;
            mawb_no = ""; location = ""; carrier = ""; flight_no = "";
            userid = user;
             // getdata();
            
            
            
        }

        private void dataforsearch()
        {
            //MessageBox.Show(mawb_no);
            //MessageBox.Show(carrier);
            //MessageBox.Show(flight_no);
            //MessageBox.Show(flight_date);
            //MessageBox.Show(location);
            if (flight_date == "")
            {
                label6.Visible = true;
                label6.Text = "Insert Flight Date";
            }
            else
            {
                strsql = "Select * from v_hht_inventory where display_flight_date=@flight_date";
                if (mawb_no != "")
                {
                    mawb_no = mawb_no.Substring(0, 3) + "-" + mawb_no.Substring(3, mawb_no.Length - mawb_no.Substring(0, 3).Length);
                    strsql = "Select * from v_hht_inventory where display_mawb=@mawb_no and display_flight_date=@flight_date";

                }
                else if (carrier != "")
                {
                    strsql = "Select * from v_hht_inventory where carrier=@carrier and display_flight_date=@flight_date";
                }
                else if (flight_no != "")
                {
                    strsql = "Select * from v_hht_inventory where flight_number=@flight_number and display_flight_date=@flight_date";
                }
                
                else if (location != "")
                {
                    strsql = "Select * from v_hht_inventory where location=@location and display_flight_date=@flight_date";
                }
            }
            


            lc.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            ds = lc.SearchRetriev(strsql, mawb_no, location, carrier, flight_no,flight_date);






        }
        
        
        
        //private void getdata()
        //{
            
            

        //    lc.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
        //    ds = lc.Getdata(mawb_no);
        //    if (ds==null)
        //    {
        //        label6.Visible = true;
        //        label6.Text = "Data not found";
        //    }
        //    else
        //    {
        //        //if (mawb_no=="160-11223344")
        //        //{
        //            //DateTime dt = new DateTime();
        //            //string timef;

        //            //timef = ds.Tables[0].Rows[0]["flight_date"].ToString();
        //            //dt = DateTime.Parse(timef);
        //            //// string t= String.Format("{0:dd}", dt);
        //            ////textBox1.Text = ds.Tables[0].Rows[0]["carr"].ToString();
        //            ////textBox2.Text = ds.Tables[0].Rows[0]["flight_no"].ToString();
        //            //dateTimePicker1.Value = dt;
        //            //dateTimePicker1.Format = DateTimePickerFormat.Custom;
        //            //dateTimePicker1.CustomFormat = "d/MM/yyyy";
        //        //}
        //        //else
        //        //{
        //        //    label6.Visible = true;
        //        //    label6.Text = "Data not found";
        //        //}
               

        //    }
        //}

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Form1 menu = new Form1(userid);
            menu.Show();
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            //bool c=false;
            //string mawb_no = textBox4.Text;
            dataforsearch();
           // lc.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
           
           // c = lc.ScanMAWB(m);
            //string l = textBox5.Text.Trim();
           // string ma = "";
            //ma = ds.Tables[0].Rows[0]["mawb_no"].ToString();
           // string loc = ds.Tables[0].Rows[0]["loc"].ToString().Trim();
            if ( ds!=null )          //Does the MAWB exists in the inventory                                          
            {

                //ds = lc.Getdata(mawb_no);
                Form3 f3 = new Form3(userid,ds, mawb_no);
                f3.Show();
            }
            else
            {
                label6.Visible = true;
                label6.Text = "MAWB does not exist";

            }
            
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            mawb_no = textBox4.Text;
            
            
            //if (mawb_no.Length==12)
            //{
            //    getdata();
            //    textBox5.Focus();
            //}
            //else
            //{
            //    //MessageBox.Show(mawb_no.Length.ToString());
            //}
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            carrier = textBox1.Text;
            
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            flight_no = textBox2.Text;
           
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            flight_date = dateTimePicker1.Text;
          
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            location = textBox5.Text;
           
        }
    }
}